﻿@{
    ViewBag.Title = "外委库盘点单据信息";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var autoSearch = true;
    var number = '@ViewBag.number';
    $(function () {
        initControl();
        gridList();
        $('#FProductionNO').on("change", function () {
            if (autoSearch) {
                $('#productionNO').val($('#FProductionNO').val());
                $('#productionNO').focus();
                $('#btn_search').click();
            } else {
                autoSearch = true;
            }
        });
    });
    function initControl() {
        var FDocuNO = $.request("FDocuNO");
        if (!!FDocuNO) {
            $('#FDocuNO').val(FDocuNO);
        }
        var FDocuNOShow = $.request("FDocuNOShow");
        if (!!FDocuNOShow) {
            $('#FDocuNOShow').val(FDocuNOShow);
        }
        var FHappenComNO = $.request("FHappenComNO");
        //if (!!FHappenComNO) {
        //    $('#FHappenComNO').val(FHappenComNO);
        //}
        var FDescription = $.request("FDescription");
        if (!!FDescription) {
            $('#FDescription').val(FDescription);
        }
        var FDocuTypeNO = $.request("FDocuTypeNO");
        if (!!FDocuTypeNO) {
            $('#FDocuTypeNO').val(FDocuTypeNO);
        }
        var FCurDate = $.request("FCurDate");
        if (!!FCurDate) {
            $('#FCurDate').val(FCurDate);
        }
        var FCredence = $.request("FCredence");
        if (!!FCredence) {
            $('#FCredence').val(FCredence);
        }
        if (FDocuNO != '') {
            lockInputById("#item");
        }
        initBindSelect("#form1");

        //零件编号 
        $("#FProductionNO").bindSelect({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStorKW/SelectPartForDropList",
            id: "FProductionNO",
            text: "FProductionNO",
            search: true
        });
        initHappenCom($('#FDocuTypeNO').val(), FHappenComNO);
        $('#FDocuTypeNO').on("change", function () {
            initHappenCom($('#FDocuTypeNO').val(), undefined);
        });
        initFStoreSetNO($("#FStoreNO").val());
        $('#FStoreNO').on("change", function () {
            initFStoreSetNO($("#FStoreNO").val());
        });
        
        $('#FQuantity').on("blur", function () {
            do_calculate_container_quantity();
            do_calculate_pallet_quantity();
        });
        $('#FFactContent').on("blur", function () {
            do_calculate_container_quantity();
            do_calculate_pallet_quantity();
        });
        $('#IsEmptyBox').on("click", function () {
            do_calculate_container_quantity();
            do_calculate_pallet_quantity();
        });
        $('#FCuaontainerQntity').on("blur", function () {
            do_calculate_pallet_quantity();
        });
        $('#FPalletFactContent').on("blur", function () {
            do_calculate_pallet_quantity();
        });
    }
    function initHappenCom(flag, value) {
        $("#FHappenComNO").empty();
        $("#FHappenComNO").bindSelect2({
            url: "/WareHouse/OutEntrust/GetHappenCompanyListJson?type=" + flag,
            id: "UnitNO",
            text: "UnitNOShortName",
            value: value,
            search: false
        });
    }
    function initFStoreSetNO(storeNO) {
        $("#FStoreSetNO").empty();
        $("#FStoreSetNO").bindSelect({
            url: "/WareHouse/OutEntrust/GetStoreHouseSetListJson",
            id: "FStoreSetNO",
            text: "FStoreSetNO",
            param: { storeNO: storeNO },
            search: false
        });
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/WareHouse/OutEntrust/GetFProductionWWOutListJson",
            postData: $("#condition").formSerialize(),
            height: 160,
            colModel: [
                { label: '单据编号', name: 'FDocuNO', width: 80, align: 'left', sortable: false },
                //{ label: '单据日期', name: 'FCurrDate', width: 80, align: 'left', sortable: false },
                { label: '零件编号', name: 'FProductionNO', width: 80, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 80, align: 'left', sortable: false },
                { label: '库存数量', name: 'FInventoryQuantity', width: 80, align: 'left', sortable: false },
                { label: '仓库编码', name: 'FStoreNO', width: 80, align: 'left', sortable: false },
                { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left', sortable: false },
                { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left', sortable: false },
                { label: '标准装箱', name: 'Fcontent', width: 80, align: 'left', sortable: false },
                { label: '托盘编号', name: 'PalletNO', width: 80, align: 'left', sortable: false },
                { label: '标准容量', name: 'FPalletContent', width: 80, align: 'left', sortable: false },
                { label: '制造单位', name: 'FProCompanyNO', width: 80, align: 'left', sortable: false },
                { label: '制造单位名称', name: 'FProCompanyName', width: 80, align: 'left', sortable: false },
                { label: '零件分类(隐藏)', name: 'FProductionTypeNO', width: 80, align: 'left', sortable: false },
                { label: '零件分类', name: 'FProductionTypeName', width: 80, align: 'left', sortable: false },
                { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'left', sortable: false },
                { label: '入库日期', name: 'FCreateDate', width: 80, align: 'left', sortable: false }
            ],
            pager: "#gridPager",
            sortname: 'FCreateDate DESC,FCreateTime DESC, FProductionNO ASC',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                autoSearch = false;
                //$("#detail1").formSerialize(rowData, "");
                //$("#detail2").formSerialize(rowData, "");
                $(".detailForm").formSerialize(rowData, "");
                $("#FProductionType").val(rowData.FProductionTypeNO + ' ' + rowData.FProductionTypeName);
                $("#FSourceDouNO").val(rowData.FDocuNO);
                if ($('#FFactContent').val() == "") {
                    $('#FFactContent').val($('#Fcontent').val());
                }
                if ($('#FPalletFactContent').val() == "") {
                    $('#FPalletFactContent').val($('#FPalletContent').val());
                }
                do_calculate_container_quantity();
                do_calculate_pallet_quantity();
            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                }
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: $("#condition").formSerialize(),
            }).trigger('reloadGrid');
        });
    }
    function btn_ok() {
        if (!$('#form1').formValid()) {

        } else {
            var param = $("#item").formSerialize();
            var detail = $(".detailForm").formSerialize();
            detail["FDescription"] = detail["FDescription2"];
            param["detail"] = JSON.stringify(detail);
            $.submitForm({
                url: "/WareHouse/OutEntrust/SubmitOutEntrustShelvesForm?status=I",
                param: param,
                close: false,
                success: function (result) {
                    setDataByJson('#item', result.data);
                    if ($('#FDocuNO').val() != '') {
                        $('#FDocuNOShow').val($('#FDocuNO').val());
                    }
                    lockInputById("#item");
                    $('#FDescription').prop("disabled", false);
                    emptyDataById("#detail");
                    initBindSelect("#detail");
                    var father = $.currentSubSubWindow().frames["Detail"];
                    father.reloadPageData($("#item").formSerialize());
                }
            })
        }
    }
    function btn_cancel() {
        var father = $.currentSubSubWindow().frames["Detail"];
        father.$.detailCloseTop();
    }
    function do_calculate_container_quantity() {
        if ($('#FQuantity').val() != '' && $('#FFactContent').val() != "") {
            var FQuantity = Math.abs(parseInt($('#FQuantity').val()));
            var FFactContent = parseInt($('#FFactContent').val());
            var FContainerQuantity = parseInt(FQuantity / FFactContent) + 1;
            if ($('#IsEmptyBox').prop("checked") || FQuantity % FFactContent == 0) {
                FContainerQuantity = FContainerQuantity - 1;
            }
            $('#FContainerQuantity').val(FContainerQuantity);
        }
    }
    function do_calculate_pallet_quantity() {
        //alert($('#FContainerQuantity').val());
        if ($('#FContainerQuantity').val() != '' && $('#FPalletFactContent').val() != "") {
            var FContainerQuantity = parseInt($('#FContainerQuantity').val());
            var FPalletFactContent = parseInt($('#FPalletFactContent').val());
            var FPalletQuantity = parseInt(FContainerQuantity / FPalletFactContent) + 1;
            if (FContainerQuantity % FPalletFactContent == 0) {
                FPalletQuantity = FPalletQuantity - 1;
            }
            $('#FPalletQuantity').val(FPalletQuantity);
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div style="padding-top: 1px;margin-left:10px;margin-right:10px;">
        <form id="form1">
            <table id="item" class="form" style="margin:10px 0;">
                <tr>
                    <th class="formTitle" style="width:60px;">发生方式</th>
                    <td class="formValue" style="width:220px;">
                        <select id="FDocuTypeNO" name="FDocuTypeNO" class="form-control required">
                            @foreach (var item in ViewBag.fdocutypenoList)
                            {
                                <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                            }
                        </select>
                    </td>
                    <th class="formTitle" style="width:60px;">摘要说明</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FDescription" name="FDescription" type="text" class="form-control" />
                    </td>
                    <th class="formTitle" style="width:60px;">单据编号</th>
                    <td class="formValue">
                        <input id="FDocuNOShow" name="FDocuNOShow" type="text" class="form-control" disabled="disabled" value="" />
                        <input id="FDocuNO" name="FDocuNO" type="hidden" value="">
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">盘点单位</th>
                    <td class="formValue">
                        <select id="FHappenComNO" name="FHappenComNO" class="form-control required">
                        </select>
                    </td>
                    <th class="formTitle">单据日期</th>
                    <td class="formValue">
                        <input id="FCurDate" name="FCurDate" type="text" class="form-control input-wdatepicker required" onfocus="WdatePicker()" />
                    </td>
                    <th class="formTitle">凭证编号</th>
                    <td class="formValue">
                        <input id="FCredence" name="FCredence" type="text" class="form-control required" value="" />
                    </td>
                </tr>
            </table>
            <hr style="margin-top:10px;margin-bottom:10px;" />
            <table id="detail1" class="form detailForm" style="border:1px solid #ddd;">
                <tr>
                    <th class="formTitle" style="width:60px;">零件编号</th>
                    <td class="formValue" style="width:220px;">
                        <select id="FProductionNO" name="FProductionNO" class="form-control required">
                        </select>
                    </td>
                    <th class="formTitle" style="width:60px;">零件名称</th>
                    <td class="formValue" style="width:220px;">
                        <input id="FProductionName" name="FProductionName" type="text" readonly="readonly" class="form-control " />
                    </td>
                    <th class="formTitle" style="width:60px;">零件分类</th>
                    <td class="formValue">
                        <input id="FProductionType" name="FProductionType" type="text" readonly="readonly" class="form-control " />
                        <input id="FProductionTypeNO" name="FProductionTypeNO" type="hidden" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">仓库编号</th>
                    <td class="formValue" style="width:160px;">
                        <select id="FStoreNO" name="FStoreNO" class="form-control required">
                            @foreach (var item in ViewBag.fstoreList)
                            {
                            <option value="@item.FStoreNO">@item.FStoreNO @item.FStoreName</option>
                            }
                        </select>
                    </td>
                    <th class="formTitle" style="width:100px;">定置编号</th>
                    <td class="formValue">
                        <select id="FStoreSetNO" name="FStoreSetNO" class="form-control required">
                        </select>
                    </td>
                    <th class="formTitle" style="width:100px;">批次号</th>
                    <td class="formValue">
                        <input id="FBatchNo" name="FBatchNo" type="text" class="form-control required" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">供货单位</th>
                    <td class="formValue" style="width:160px;">
                        <select id="FProCompanyNO" name="FProCompanyNO" class="form-control required">
                        @foreach (var item in ViewBag.fprocompanyList)
                        {
                            <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                        }
                        </select>
                    </td>
                    <th class="formTitle" style="width:100px;">开票数量</th>
                    <td class="formValue">
                        <input id="FQuantity" name="FQuantity" type="text" class="form-control text-right required isInteger" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">件</label>
                    </td>
                    <th class="formTitle" style="width:100px;">零件单价</th>
                    <td class="formValue">
                        <input id="FPrice_KP" name="FPrice_KP" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label style="margin-left:12px">元</label>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">备注</th>
                    <td class="formValue" colspan="5">
                        <input name="FDescription2" type="text" class="form-control" />
                        <input id="FSourceDouNO" name="FSourceDouNO" type="hidden" value="">
                    </td>
                </tr>
            </table>
            <table id="detail2" class="form detailForm" style="border:1px solid #ddd;margin-top:5px;">
                <tr>
                    <th class="formTitle" style="width:60px;">容器编号</th>
                    <td class="formValue" style="width:120px;">
                        <input id="FContainerNO" name="FContainerNO" type="text" readonly="readonly" class="form-control" />
                    </td>
                    <th class="formTitle" style="width:80px;">标准装箱数</th>
                    <td class="formValue" style="width:120px;">
                        <input id="Fcontent" name="FContent" type="text" class="form-control text-right digits" readonly="readonly" style="width:60px;margin-left:0px;" /><label style="margin-left:12px">件/箱</label>
                    </td>
                    <th class="formTitle" style="width:80px;">实际装箱数</th>
                    <td class="formValue" style="width:120px;">
                        <input id="FFactContent" name="FFactContent" type="text" class="form-control text-right required digits" style="width:60px;margin-left:0px;" /><label style="margin-left:12px">件/箱</label>
                    </td>
                    <td class="formValue" style="width:120px;">
                        <input id="IsEmptyBox" type="checkbox" /><label for="IsEmptyBox">是否空箱入库</label>
                    </td>
                    <th class="formTitle" style="width:60px;">容器数量</th>
                    <td class="formValue">
                        <input id="FContainerQuantity" name="FContainerQuantity" type="text" class="form-control text-right required digits" style="width:80px;margin-left:0px;" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">托盘编号</th>
                    <td class="formValue">
                        <input id="PalletNO" name="FPalletNO" type="text" readonly="readonly" class="form-control" />
                    </td>
                    <th class="formTitle">托盘标准容量</th>
                    <td class="formValue">
                        <input id="FPalletContent" name="FPalletContent" type="text" class="form-control text-right digits" readonly="readonly" style="width:60px;margin-left:0px;" /><label style="margin-left:12px">箱/托</label>
                    </td>
                    <th class="formTitle">托盘实际容量</th>
                    <td class="formValue">
                        <input id="FPalletFactContent" name="FPalletFactContent" type="text" class="form-control text-right required digits" style="width:60px;margin-left:0px;" /><label style="margin-left:12px">箱/托</label>
                    </td>
                    <td class="formValue">
                        &nbsp;
                    </td>
                    <th class="formTitle">托盘数量</th>
                    <td class="formValue">
                        <input id="FPalletQuantity" name="FPalletQuantity" type="text" class="form-control text-right required digits" style="width:80px;margin-left:0px;" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <hr style="margin-top:5px;margin-bottom:0px;" />
    <div style="margin-left: 10px; margin-right: 10px;border-bottom:1px solid #ccc;">
        <table id="condition" class="form">
            <tr>
                <th class="formTitle" style="width:60px;">零部件号</th>
                <td class="formValue" style="width:140px;">
                    <input id="productionNO" name="productionNO" class="form-control" type="text">
                    <input id="isShowZero" type="hidden" value="true" />
                </td>
                <th class="formTitle" style="width:60px;">零件名称</th>
                <td class="formValue" style="width:140px;">
                    <input id="productionName" name="productionName" class="form-control" type="text">
                </td>
                <td class="formValue">
                    <div class="btn-group" style="margin-left:10px;margin-top:3px;">
                        <a id="btn_search" class="btn btn-primary center-block btn-1 " onclick="btn_search();"><span class="glyphicon glyphicon-search"></span> 查询</a>
                    </div>
                </td>
            </tr>
        </table>
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
    <div style="text-align:right;margin-left: 10px; margin-right: 10px;padding:5px 40px;">
        <div class="btn-group" style="">
            <a id="btn_ok" class="btn btn-primary center-block" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确定</a>
        </div>
        <div class="btn-group" style="margin-left:30px;">
            <a id="btn_cancel" class="btn btn-danger center-block" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 关闭</a>
        </div>
    </div>
</div>